<?php
// +----------------------------------------------------------------------
// | NewThink [ Think More,Think Better! ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2018 http://www.newthink.cc All rights reserved.
// +----------------------------------------------------------------------
// | 版权所有：山西创泰网络科技有限公司
// +----------------------------------------------------------------------
// | Author: 子弹兄  Date:2019-03-01 Time:17:08
// +----------------------------------------------------------------------
namespace app\test\controller;

use think\facade\Request;

class Test
{

    public function test()
    {
        $typeArr = [
            ['id' => 1,'name' => 'PM2.5'],
            ['id' => 3,'name' => '二氧化硫'],
            ['id' => 4,'name' => '氮氧化物'],
        ];
        $randomKeys=array_rand($typeArr);
        print_r($typeArr[$randomKeys]);
    }


    public function test2()
    {
        $typeArr = ['1','2','3'];
        $randomKeys=array_rand($typeArr);
        print_r($typeArr[$randomKeys]);
    }

    public function test3()
    {
        echo mt_rand(-20, 20);
    }

    /**
     * 用 PHP 计算样本相关系统
     * @author hongwei 2019-03-25 整理并翻译为简体中文
     * @url https://yhhuang1966.blogspot.com/2013/08/php_4.html
     */
    public function correlationAnalysis()
    {
        $x          = [25, 23, 27, 35, 30];
        $y          = [35, 27, 36, 45, 42];
        $result = correlationAnalysis($x, $y);
        echo $result;
    }

    /**
     * 计算网格的数据有多少
     * 说明：平工说总数是 72*63 ＝ 4536 个
     * 而我计算出来的数量是：3111 个
     * 气象的nc网格化数据是61*51=3111，不需要坐标
     * 19 。。。。。。。
     * 13 14 15 16 17 18
     * 07 08 09 10 11 12
     * 01 02 03 04 05 06
     */
    public function countGridNumber()
    {
        $path = Request::root().'../database/seeds/json/nc.json';
        $data = file_get_contents($path);
        $array = json_decode($data, true);
        $value = $array['pm2.5_grid'];
        $arrayComma = explode(',', $value);
        $number = count($arrayComma);
        echo $number;
    }
}
